import { getCurrentInstance } from 'vue';
import { ElMessage, type FormInstance, ElMessageBox } from 'element-plus';
import { ANY_OBJECT } from '@/types/generic';
import { useLoginStore, useLayoutStore } from '@/store';
import { post, get } from '@/common/http/request';
import { Dialog } from '@/components/Dialog';
import { OnlineApiController } from '@/api/online';

export const useFormExpose = (
  formData: ANY_OBJECT,
  props?: ANY_OBJECT,
  router?: ANY_OBJECT,
  options?: ANY_OBJECT,
) => {
  const loginStore = useLoginStore();
  const layoutStore = useLayoutStore();
  const _this = getCurrentInstance();

  return {
    formData,
    props: _this?.props,
    formProps: props,
    loginStore,
    layoutStore,
    ElMessage,
    ElMessageBox,
    router,
    Dialog,
    showDialog: options?.showDialog,
    showOnlineDialog: options?.showOnlineDialog,
    showDictSelectDlg: options?.showDictSelectDlg,
    showSelectDialog: options?.showSelectDialog,
    getFormWidget: () => {
      return options?.formRef?.value;
    },
    showMessage: (type: string, message: string) => {
      ElMessage[type](message);
    },
    close: options?.close,
    refresh: options?.refresh,
    axios: {
      post,
      get,
    },
    tableInstance: options?.tableInstance,
    runScriptApi: OnlineApiController.runScript,
  };
};
